package org.sp.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.Objects;

/**
 * @author 76986
 */
public class HibernateUtil {

    private static SessionFactory sessionFactory;
    private static Boolean flag = false;
    private HibernateUtil(){
        if (flag){
            throw new RuntimeException();
        }
    }

    public static SessionFactory getInstance(){
        if (Objects.isNull(sessionFactory)){
            synchronized (HibernateUtil.class){
                if (Objects.isNull(sessionFactory)){
                    sessionFactory = new Configuration().configure("hibernate-conf.xml").buildSessionFactory();
                    flag = true;
                }
            }
        }
        return sessionFactory;
    }

}
